home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / E.T.O. #4 Installer / DoIt < prev    next >
Text File  |  1991-05-23  |  6KB  |  179 lines

  1. #
  2. #    NAME:
  3. #        Doit
  4. #
  5. #    SYNTAX:
  6. #        Doit (CommandFile [-echo] [-dump]) | [-selection]
  7. #
  8. #    SYNOPSIS:
  9. #        Doit will execute a series of shell commands hilighting each command
  10. #        as it is executed.  The commands can be in either a file or the
  11. #        current selection.  If a CommandFile is passed to doit the file is
  12. #        opened (as the active window) and each line (multiple lines if a "∂"
  13. #        is present at the end of a line) is executed.  The window
  14. #        is closed when all the commands have been processed.
  15. #
  16. #    OPTIONS:
  17. #        -e[cho]            Each command is echo to the Worksheet before execution.
  18. #        -d[ump]            If an error occurs in one of the commands all the
  19. #                            remaining commands (including the command that failed)
  20. #                            are written to the Worksheet and marked by "ToDo".
  21. #        -s[election]    Execute the commands in the current selection.
  22. #
  23. #    SPECIAL NOTE:
  24. #        The initial overhead is fairly substantial (on a MacPlus) when executing
  25. #        commands from the current selection.  For a 10 line selection it takes
  26. #        26 seconds of "pre-processing" before doit starts to execute the 
  27. #        first command.  If the same 10 lines were in a file the overhead is
  28. #        only 11 seconds.  Once execution begins the overhead is small in either
  29. #        case.
  30. #
  31. #        This script does not work correctly on structured commands.
  32. #
  33. #    AUTHOR:
  34. #        Peter J. Potrebic
  35. #        Copyright Apple Computer, Inc. 1988-9
  36. #        All Rights Reserved.
  37. #
  38.  
  39. Unset ErrFile
  40. Unset CommandFile
  41. Unset EchoCmds
  42. Unset DumpCmds
  43. Unset CurSel
  44.  
  45. Set Cmd "{0}"
  46. Set Syntax "(CommandFile [-echo] [-dump]) | [-selection]"
  47. Set Error 0
  48.  
  49. For Arg In {"Parameters"}                            # Parse the command line
  50.  
  51.     # Checking for the echo option - echo commands before they are executed
  52.     If "{Arg}" == "-e" || "{Arg}" == "-echo"
  53.         If {EchoCmds} == 0
  54.             Set EchoCmds 1
  55.         Else
  56.             Echo "### {Cmd} - option ∂"{Arg}∂" multiply defined"
  57.             Set Error 1
  58.         End
  59.  
  60.     # Checking for the dump option - echo unexecuted commands after error
  61.     Else If "{Arg}" == "-d" || "{Arg}" == "-dump"
  62.         If {DumpCmds} == 0
  63.             Set DumpCmds 1
  64.         Else
  65.             Echo "### {Cmd} - option ∂"{Arg}∂" multiply defined"
  66.             Set Error 1
  67.         End
  68.     
  69.     # Checking for the selection option - commands are in the current selection
  70.     Else If "{Arg}" == "-s" || "{Arg}" == "-selection"
  71.         If {CurSel} == 0
  72.             Set CurSel 1
  73.         Else
  74.             Echo "### {Cmd} - option ∂"{Arg}∂" multiply defined"
  75.             Set Error 1
  76.         End            
  77.  
  78.     # Found unknown option
  79.     Else If "{Arg}" =~ /-≈/ || "{Arg}" == -
  80.         Echo "### {Cmd} - ∂"{Arg}∂" is not an option"
  81.         Set Error 1
  82.     
  83.     # Found the command file
  84.     Else
  85.         If "{CommandFile}" == 0
  86.             Set CommandFile "{Arg}"
  87.         Else
  88.             Echo "### {Cmd} - Too many parameters were specified."
  89.             Set Error 1
  90.         End
  91.     End
  92. End > Dev:StdErr
  93.  
  94. If {CurSel} && ({DumpCmds} || {EchoCmds})
  95.     Echo "### {Cmd} - conflicting options were specified"
  96.     Set Error 1
  97. End > Dev:StdErr
  98.  
  99. If ("{CommandFile}" == "" && !{CurSel})
  100.     Echo "### {Cmd} - No command file specified"
  101.     Set Error 1
  102. End > Dev:StdErr
  103.  
  104. If {Error}                                            # Were there any syntax errors?
  105.     Echo "# Usage - {Cmd} {Syntax}"
  106.     Exit {Error}                                    # Exiting (because of syntax error)
  107. End > Dev:StdErr
  108.  
  109. #
  110. #                EXECUTING THE CURRENT SELECTION...
  111. #
  112. If {CurSel}
  113.     Set Exit 0                                        # Ignore errors in the replace
  114.     Mark -y § Doit "{Active}"                    # mark all the commands to be executed
  115.     Set MyActive "{Active}"
  116.     Set NumCmds `Count -l "{MyActive}".§`
  117.     
  118.     If {NumCmds} > 0
  119.         Set NumEscapes `search -q /≈∂∂∞/ "{MyActive}".§ ≥ dev:null | Count -l` 
  120.         Evaluate NumCmds = {NumCmds} - {NumEscapes}
  121.     
  122.         Find ΔDoit "{MyActive}"                        # Goto top of Commands to be executed
  123.         
  124.         Set cCmd 0                                        # Initialize command counter
  125.         Loop
  126.             Find /•/ "{MyActive}"                    # Find beginning of next line
  127.             Find §:/[¬∂∂]∞/ "{MyActive}"            # Find from § to end of command
  128.             Evaluate cCmd += 1                        # Increment command counter
  129.             Execute "{MyActive}".§                    # Execute the command
  130.             Set Error {Status}                        # Capture and save status
  131.             Break If ({Error} != 0 || {cCmd} == {NumCmds})
  132.         End
  133.         Find §!1 "{MyActive}"                        # go to line after last command
  134.     End
  135.     UnMark Doit "{MyActive}"
  136.  
  137. #
  138. #                EXECUTING THE FROM A FILE...
  139. #
  140. Else
  141.     Set ToDo "#### Still ToDo… ####"
  142.     Open -t "{CommandFile}"                            # Open command file as a target window
  143.     Zoomwindow -b "{CommandFile}"                    # Zoom the command file to its full size
  144.     Open "{CommandFile}"                                # Open command file as active window
  145.     Exit {Status} If {Status} != 0
  146.     Set MyActive "{Active}"
  147.     Set Exit 0                                        # Ignore errors in the replace
  148.     Find • "{MyActive}"                            # Goto top of File to be executed
  149.     Loop                                                # Loop through all commands
  150.         Find /•/ "{MyActive}"                    # Find beginning of next line
  151.         Break If {Status}    != 0                    # At end of file
  152.         Find §:/[¬∂∂]∞/ "{MyActive}"            # Find from § to end of command
  153.         Break If {Status}    != 0                    # At end of file
  154.         If {EchoCmds}
  155.             Catenate "{MyActive}".§ >> "{Worksheet}".§    # Write command to Standard Output
  156.             Echo >> "{Worksheet}".§                                # Echo a newline after the command
  157.         End
  158.         Execute "{MyActive}".§                    # Execute the command
  159.         Set Error {Status}                        # Capture and save status
  160.         If {Error} != 0                            # There was an error
  161.             If {DumpCmds}                                # List the commands left to execute
  162.                 Echo "{ToDo}" >> "{Worksheet}".§    # List includes the command that failed
  163.                 Find §:∞ "{MyActive}"                # Select the unexecuted commands
  164.                 Catenate "{MyActive}".§ >> "{Worksheet}".§    # Write commands to Standard Output
  165.             #    Echo
  166.             #    Mark -y §¡1:\{ToDo}\ ToDo    "{Worksheet}" # Mark the commands that weren't executed                                                                            
  167.  
  168. ### CHK 3/15/90 Discard the above 2 line and add the following line to fix the bug #......
  169.  
  170.                 Mark -y § ToDo    "{Worksheet}" # Mark the commands that weren't executed                                                                            
  171.             End
  172.             Break
  173.         End
  174.     End
  175.  
  176.     Close "{MyActive}" ≥ dev:null                # Close the command file
  177. End
  178. Exit "{Error}"                                        # return with proper status
  179.